package com.zzzy.service;


import com.zzzy.config.DataSource;
import com.zzzy.po.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class UserServiceImpl implements UserService {

    @Autowired
    //@Qualifier(value = "primaryJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    @DataSource
    public User findUser( int id) {
        String sql = "select id,name,age from user where id=" + id;
        User user = null;
        List<User> userList = jdbcTemplate.query(sql, new Object[]{}, new BeanPropertyRowMapper<User>(User.class));
        if(null!=userList&&userList.size()>0){
            user = userList.get(0);
        }
        return user;
    }
}
